﻿package com.thorqq.magictimer.action;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import com.thorqq.magictimer.core.TimerAbs;
import com.thorqq.magictimer.util.Util;

/**
 * 发送虚拟短信
 * 
 */
public class ActionSendVirtualSMS extends ActionSendSMS
{
    private static final long serialVersionUID = -7994698361899870845L;

    public ActionSendVirtualSMS(int id, int execOrder, String actionType, String param)
    {
        super(id, execOrder, actionType, param);
    }

    @Override
    public boolean run(Context context, TimerAbs timer)
    {
        this.paramToString();
        
        for (String key : mPhoneNumber.keySet())
        {
            try
            {
                ContentValues values = new ContentValues();
                // 发送时间
                values.put("date", System.currentTimeMillis());
                // 阅读状态  1已读 0未读
                values.put("read", 1);
                // 1为收 2为发
                values.put("type", 2);
                // 送达号码
                values.put("address", key);
                // 送达内容
                values.put("body", mContent);
                // 插入短信库
                context.getContentResolver().insert(Uri.parse("content://sms/sent"),
                        values);
                Util.log("Receive virtual sms from " + mPhoneNumber.get(key) + "|" + key);            } 
            catch (Exception e)
            {
                Util.log_ex(e);
            }
        }

        return true;
    }

    @Override
    public String getName()
    {
        return "发送虚拟短信";
    }

}
